﻿/**
 *	html/pem_data.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-07-13		create the file
 */

/**
 *	init data model
 */
function init_data_model()
{
    _init_button_tree_map();

    init_user();		// in "data/pem_data_user.js"
    init_host();		// in "data/pem_data_system.js"
    init_tunnel();		// in "data/pem_data_tunnel.js"
    init_device();		// in "data/pem_data_device.js"
    init_protocal();	// in "data/pem_data_protocal.js"
    init_alarm();		// in "data/pem_data_alarm.js"
    init_event();		// in "data/pem_data_event.js"
    init_scene();		// in "data/pem_data_scene.js"
}

/**
 *	load data from db
 */
function load_data()
{
    qt_html.load_host();
    qt_html.load_tunnel_type();
    qt_html.load_tunnel();
    qt_html.load_device_type();
    qt_html.load_protocal();
    qt_html.load_device();
    qt_html.load_alarm();
    qt_html.load_event_type();
    qt_html.load_event();
    qt_html.load_scene();

    // the last event to create main frame
    qt_html.load_frame();
}

/**
 * init map between buttons and tree panels
 *	button ids are defined in "pem_north.js"
 *	tree ids are defined in "pem_west.js"
 */
var g_btn_tree_map;
function _init_button_tree_map()
{
    g_btn_tree_map								= new Array();
    g_btn_tree_map["btn_env_monitor"]			= "tree_panel_monitor";
    g_btn_tree_map["btn_security_monitor"]		= "tree_panel_security";
    g_btn_tree_map["btn_video_monitor"]			= "tree_panel_video";
    g_btn_tree_map["btn_option_manage"]			= "tree_panel_option";
    g_btn_tree_map["btn_alarm_event"]			= "tree_panel_alarm";
    g_btn_tree_map["btn_system_manage"]			= "tree_panel_system";
}

/**
 *	callback for creating main panel
 */
function callback_create_main()
{
    create_main_panel();
}

/**
examples for Ext.data.ArrayStore
////////////////////////////////////////////////////////////////////////////////
// insert
g_tunnel.insert( 0, [[3, 56, ],[2122,343,4343]] );
alert( g_tunnel.getAt(1).get("type") );

////////////////////////////////////////////////////////////////////////////////
// modify
g_tunnel.getAt(0).set("type", "newtype");
alert( g_tunnel.getAt(0).get("type") );

////////////////////////////////////////////////////////////////////////////////
// remove record "function removeAt( index, count )"
// g_tunnel.removeAt( 0, 1 );

////////////////////////////////////////////////////////////////////////////////
// traversal
var msg = ["arrays:"];
g_tunnel.each( function( rec ){
   msg.push( "id=" + rec.get("id") + ", name=" + rec.get("name") );
});
alert( msg.join("\n") );

////////////////////////////////////////////////////////////////////////////////
// get record by index and session
alert( g_tunnel.getAt(1).get("remark") );
*/

